package com.example.demo.websoket.controller;

import com.example.demo.websoket.entity.WsMessage;
import com.example.demo.websoket.handler.WebSocketHandlerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class SocketController {

    @Autowired
    private WebSocketHandlerImpl handler;

    @RequestMapping("/")
    public String index() {
        return "index";
    }


    @RequestMapping("/sendAll")
    public @ResponseBody
    String sendAll(WsMessage clientMessage) {
        try {
            //handler.sendMessageToAllUsers(clientMessage);
            return "发送成功";
        } catch (Exception e) {
            e.printStackTrace();
            return "发送失败";
        }
    }

    /**
     * 根据科室发送
     *
     * @return
     */
    @RequestMapping("/sendToDepartMent")
    public @ResponseBody
    String sendToDepartMent(WsMessage clientMessage) {
        handler.sendMsgToMq(clientMessage);
        return "发送成功";
    }

}